package copyengine.ui.component.button.animation
{
    import starling.display.DisplayObject;
    import starling.events.Touch;
    import starling.filters.ColorMatrixFilter;

    public class CEColorFilterButtonAnimation implements ICEButtonAnimation
    {
        private var mTarget:DisplayObject;
        private var mIsEnable:Boolean = true;
        private var mTouchDownFilter:ColorMatrixFilter;
        private var mDisableFilter:ColorMatrixFilter;

        public function CEColorFilterButtonAnimation()
        {
        }

        public function initialize(_target:DisplayObject):void
        {
            mTarget = _target;

            mTouchDownFilter = new ColorMatrixFilter();
            mTouchDownFilter.adjustBrightness(-0.3); //亮度
            //mTouchDownFilter.adjustContrast(0); //对比度
            //mTouchDownFilter.adjustHue(0); //色相
            //mTouchDownFilter.adjustSaturation(0); //饱和度

            mDisableFilter = new ColorMatrixFilter();
            mDisableFilter.adjustSaturation(-1);
        }

        public function dispose():void
        {
            mTouchDownFilter && mTouchDownFilter.dispose();
            mDisableFilter && mDisableFilter.dispose();
        }

        public function onTouchDown(_touch:Touch):void { mIsEnable == true ? mTarget.filter = mTouchDownFilter : null; }

        public function onTouchUp(_touch:Touch):void { mIsEnable == true ? mTarget.filter = null : null; }

        public function set isEnabled(_value:Boolean):void
        {
            mTarget.filter = _value == false ? mDisableFilter : null;
            mIsEnable = _value;
        }

    }
}
